﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sodao.FastSocket.Server.Messaging
{
    /// <summary>
    /// 16进制字节数组传输
    /// </summary>
    public class ByteDataMessage:Messaging.IMessage
    {
        #region Public Members
        /// <summary>
        /// 
        /// </summary>
        public byte direct = 0x00;
        /// <summary>
        /// 
        /// </summary>
        public byte main_cmd = 0x00;
        /// <summary>
        /// 
        /// </summary>
        public byte sub_cmd = 0x00;
        /// <summary>
        /// 
        /// </summary>
        public ushort squence = 0x0000;
        /// <summary>
        /// 
        /// </summary>
        public List<byte> dataArry = new List<byte>();

    
        #endregion

        #region Constructors
      /// <summary>
      /// 
      /// </summary>
      /// <param name="main_cmd_param"></param>
      /// <param name="sub_cmd_param"></param>
      /// <param name="databuf"></param>
        public ByteDataMessage(byte direct_param, ushort squence_param, byte main_cmd_param,byte sub_cmd_param, byte []databuf)
        {
            if (databuf == null) throw new ArgumentNullException(" ByteDataMessage buf null");
            this.direct = direct_param;
            this.main_cmd = main_cmd_param;
            this.sub_cmd = sub_cmd_param;
            this.squence = squence_param;
            this.dataArry.AddRange(databuf);
        }
        #endregion


        #region Public Methods
/// <summary>
/// 
/// </summary>
/// <param name="connection"></param>
/// <param name="data"></param>
/// <exception cref="ArgumentNullException"></exception>
        public void Reply(SocketBase.IConnection connection,ref byte [] data)
        {
            if (connection == null) throw new ArgumentNullException("connection");
            connection.BeginSend(ToPacket(ref data));
        }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="data"></param>
    /// <returns></returns>
    /// <exception cref="ArgumentNullException"></exception>
        static public SocketBase.Packet ToPacket(ref byte[] data)
        {
            if (data == null) throw new ArgumentNullException("bye buf null");
            return new SocketBase.Packet(data);
        }
        #endregion

    }
}
